package org.jh;

import org.junit.Test;
import org.junit.Before;

import static org.junit.Assert.*;

class TransferServiceTest {
	def service = new TransferService()
	def acc1
	def acc2
	
	@Before void setupAccount() {
		acc1 = new Account("A", 100)
		acc2 = new Account("B", 30)
	}
	
	@Test void transferOk() {
		service.transactionalTransfer(acc1, acc2, 100)
		assert 0 == acc1.balance &&  130 == acc2.balance
	}
	
	@Test void negativeBalanceTransfer() {
		try {
			service.transactionalTransfer(acc1, acc2, 150)
			assert false, "Should throws exception!!"
		} catch (Exception e) {}
		assert 100 == acc1.balance && 30 == acc2.balance
	}
	
	@Test void negativeBalanceNonTxTransfer() {
		try {
			service.nonTransactionalTransfer(acc1, acc2, 150)
			assert false, "Should throws exception!!"
		} catch (Exception e) {}
		assert 100 == acc1.balance && 180 == acc2.balance
	}
}
